// pages/storeManage/storeManage.js
import util from '../../utils/util'
import http from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: {},
    storeInfo: {},
    operateList: [
      {
        text: '店铺装修',
        img: '../../assets/storeManage/store.png',
        page: '/pages/storeManage/storeConstruction/storeConstruction'
      }, {
        text: '发布公告',
        img: '../../assets/storeManage/placard.png',
        page: '/pages/storeManage/annouce/annouce'
      }, 
      // {
      //   text: '联系客服',
      //   img: '../../assets/storeManage/customer.png',
      //   method: true
      // }, 
      {
        text: '店铺信息',
        img: '../../assets/storeManage/info.png',
        page: '/pages/storeManage/storeInfo/storeInfo'
     }, 
     {
       text:'商品管理',
       img: '../../assets/storeManage/release.png',
       page:'/pages/storeManage/commodity/commodity'
     }
       // {
      //   text: '发布商品',
      //   img: '../../assets/storeManage/release.png'
      // }, {
      //   text: '报名活动',
      //   img: '../../assets/storeManage/active.png'
      // }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      'userInfo.isAdmin': options.admin == 'true' ? true : false,
      'userInfo.id': options.businessId
    })
    this.getStoreInfo()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },
  WeixinServer(){
    wx.openCustomerServiceChat({
      extInfo: {
        url:'https://work.weixin.qq.com/kf/' + "kfc11f5184d7762c658"
      },
      corpId: 'ww106853c8ad050781',
    })
  },
  getStoreInfo() {
    http.get('/api/store/v1/user/home').then(res => {
      const { name } = res.data.list.filter(item => item.id === this.data.userInfo.id)[0]
      if (res.code === 200) {
        this.setData({
          storeInfo: res.data,
          'userInfo.img': res.data.list.filter(item => item.id === this.data.userInfo.id)[0].img,
          'userInfo.name': name
        })
      }
    })
  },

  linkToPage(e) {
    const { page: url, method } = e.currentTarget.dataset
    if (url) {
      wx.navigateTo({
        url: url + `?id=${this.data.userInfo.id}&admin=${this.data.userInfo.isAdmin}`
      })
    } else if (method) {
      wx.openCustomerServiceChat({
        extInfo: {
          url: 'https://work.weixin.qq.com/kfid/kfc2b6c8fe7f848fd26',
        },
        corpId: 'ww106853c8ad050781',
        success(res) {
          console.log(res)
        },
        fail(fail) {
          console.log(fail)
        }
      })
    } else {
      wx.showToast({
        title: '敬请期待',
        icon: 'none'
      })
    }
  }
})